using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: daiduong19051986@gmail.com 
    /// <summary>
    public class RuleSetControl
    {
        #region Local Variable

        private string business;
        private RuleSetDataAccess _objDAO;
        #endregion Local Variable

        #region Method

        public RuleSetControl(String bus)
        {
            business = bus;
            _objDAO = new RuleSetDataAccess();
        }
        public RuleSetInfo Get(string db, Int32 AUTO_ID, String RULESET_CODE, ref string sErr)
        {
            return _objDAO.Get(db, AUTO_ID, RULESET_CODE, ref sErr);
        }

        public DataTable GetAll(string db, ref string sErr)
        {
            return _objDAO.GetAll(db, ref sErr);
        }

        public Int32 Add(string db, RuleSetInfo obj, ref string sErr)
        {
            return _objDAO.Add(db, obj, ref sErr);
        }

        public string Update(string db, RuleSetInfo obj)
        {
            return _objDAO.Update(db, obj);
        }

        public string Delete(string db, Int32 AUTO_ID, String RULESET_CODE)
        {
            return _objDAO.Delete(db, AUTO_ID, RULESET_CODE);
        }
        public Boolean IsExist(string db, Int32 AUTO_ID, String RULESET_CODE)
        {
            return _objDAO.IsExist(db, AUTO_ID, RULESET_CODE);
        }


        public string InsertUpdate(string db, RuleSetInfo obj)
        {
            string sErr = "";
            if (IsExist(db, obj.AUTO_ID, obj.RULESET_CODE))
            {
                sErr = _objDAO.Update(db, obj);
            }
            else _objDAO.Add(db, obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {
            RuleSetInfo inf = new RuleSetInfo();
            return inf.ToDataTable();
        }

        public string TransferIn(string db, DataRow row)
        {
            RuleSetInfo inf = new RuleSetInfo(row);
            return InsertUpdate(db, inf);
        }
        #endregion Method

        public object BeginTransaction(ref string sErr)
        {
            return _objDAO.BeginTransaction(ref sErr);

        }
        public bool CommitTransaction(ref string sErr)
        {
            return _objDAO.CommitTransaction(ref sErr);


        }
        public bool RollbackTransaction(ref string sErr)
        {
            return _objDAO.RollbackTransaction(ref sErr);


        }
        public void SetTransaction(object o)
        {
            _objDAO.SetTransaction(o);

        }

        public DataTable GetbyRuleSetCode(string db, string RuleSetCode, ref string sErr)
        {
            return _objDAO.GetbyRuleSetCode(db, RuleSetCode, ref sErr);

        }

        public DataTable GetbyRuleSetCode(string db, string RuleSetCode, string strWhere, ref string sErr)
        {
            return _objDAO.GetbyRuleSetCode(db, RuleSetCode, strWhere, ref sErr);
        }
    }
}
